package com.koron.housing.contract.service.impl;


import com.koron.housing.contract.bean.po.HousingContractRenewal;
import com.koron.housing.contract.mapper.HousingContractRenewalMapper;
import com.koron.housing.contract.service.HousingContractRenewalService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 续租记录(HousingContractRenewal)表服务实现类
 *
 * @author jzp
 * @since 2022-03-07 14:45:18
 */
@Service("renewalService")
public class HousingContractRenewalServiceImpl implements HousingContractRenewalService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public HousingContractRenewal getById(SessionFactory factory, String id) {
        HousingContractRenewalMapper mapper = factory.getMapper(HousingContractRenewalMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<HousingContractRenewal> list(SessionFactory factory, HousingContractRenewal housingContractRenewal) {
        HousingContractRenewalMapper mapper = factory.getMapper(HousingContractRenewalMapper.class);
        return mapper.selectList(housingContractRenewal);
    }

    @Override
    @TaskAnnotation("listByContractId")
    public List<HousingContractRenewal> listByContractId(SessionFactory factory, String contractId) {
        HousingContractRenewal housingContractRenewal = new HousingContractRenewal();
        housingContractRenewal.setContractId(contractId);
        return list(factory, housingContractRenewal);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, HousingContractRenewal housingContractRenewal) {
        HousingContractRenewalMapper mapper = factory.getMapper(HousingContractRenewalMapper.class);
        return mapper.insertOrUpdate(housingContractRenewal) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, HousingContractRenewal housingContractRenewal) {
        HousingContractRenewalMapper mapper = factory.getMapper(HousingContractRenewalMapper.class);
        return mapper.update(housingContractRenewal) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        HousingContractRenewalMapper mapper = factory.getMapper(HousingContractRenewalMapper.class);
        return mapper.hidden(id) > 0;
    }
}
